package com.qfedu.openplateform.manager.controller;

/**
 * @author: Mr.Shang
 * @date: 2021/10/27 19:10
 * @version: 1.0
 * @description: 应用管理
 */

import com.github.pagehelper.PageHelper;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.AppInfo;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.service.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/app_info")
public class AppInfoController {

    @Autowired
    private AppInfoService appInfoService;

    @RequestMapping("/table")
    public TableData<AppInfo> getAllAppInfo(@RequestParam(value = "page", required = false, defaultValue = "1") int pageIndex,
                                            @RequestParam(value = "limit", required = false, defaultValue = "10") int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<AppInfo> allAppInfo = appInfoService.getAllAppInfo();
        return new TableData<>(allAppInfo.size(), allAppInfo);
    }

    @RequestMapping("/del")
    public AjaxMessage deleteAppInfo(int[] ids) {
        for (int id : ids) {
            appInfoService.deleteAppInfo(id);
        }
        return new AjaxMessage(true,"删除成功");
    }

    @RequestMapping("/add")
    public AjaxMessage addAppInfo(AppInfo appInfo) {
        System.out.println(appInfo);
        appInfoService.addAppInfo(appInfo);
        return new AjaxMessage(true,"添加成功");
    }

    @RequestMapping("/update")
    public AjaxMessage updateAppInfo(AppInfo appInfo) {
        appInfoService.updateAppInfo(appInfo);
        return new AjaxMessage(true,"更新成功");
    }
}
